{include file="public/header"/}
</head>
<body>
<div class="layui-form">
<div class="layui-fluid" id="LAY-component-layer-list">
<div class="layui-col-md12 pd83">
<div class="layui-card hideshadow">
  <div class="layui-tab layui-tab-brief">
  {include file="web/top"}
  <div class="layui-tab-content">
    <div class="layui-card-header">短信配置</div>
    <div class="layui-form-item">
        <label class="layui-form-label pcfcms_layui-form-label">状态</label>
        <div class="layui-input-block">
            <input type="checkbox" name="sms_syn_weapp" lay-filter="sms_syn_weapp" value="{$config.sms_syn_weapp|default='0'}" lay-skin="switch" lay-text="开启|关闭" {notempty name="$config.sms_syn_weapp"}checked{/notempty}>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label pcfcms_layui-form-label"><b class="pcfts">*</b>短信平台</label>
        <div class="layui-input-inline pcfcms_layui-input-inline">
            <select name="sms_platform" id="sms_platform">
                <option value="1" {if($config.sms_platform == 1)}selected{/if}>创信短信</option>
                <option value="2" {if($config.sms_platform == 2)}selected{/if}>阿里云</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label pcfcms_layui-form-label"><b class="pcfts">*</b>平台[appkey]</label>
        <div class="layui-input-inline pcfcms_layui-input-inline">
            <input type="text" name="sms_appkey" id="sms_appkey" lay-verify="required" value="{$config.sms_appkey}" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label pcfcms_layui-form-label"><b class="pcfts">*</b>平台[secretKey]</label>
        <div class="layui-input-inline pcfcms_layui-input-inline">
            <input type="password" name="sms_secretkey" id="sms_secretkey" lay-verify="required" value="{$config.sms_secretkey}" class="layui-input">
        </div>
    </div>      
    <div class="layui-form-item">
        <label class="layui-form-label pcfcms_layui-form-label">短信内容</label>
        <div class="layui-input-inline pcfcms_layui-input-inline">
            <textarea name="sms_content" id="sms_content" class="layui-textarea">{$config.sms_content}</textarea>
        </div>
    </div>              
    <div class="layui-form-item">
        <label class="layui-form-label pcfcms_layui-form-label">测试短信</label>
        <div class="layui-input-inline pcfcms_layui-input-inline">
            <input type="text" name="sms_test" id="sms_test" value="{$config.sms_test}" class="layui-input">
        </div>
        <button class="layui-btn" lay-submit="sendSms" lay-filter="sendSms">发送</button>
    </div>
  </div>
  </div>
</div>
<div class="pcfclear"></div>
</div>
<div class="submit-info text-center">
    <button class="layui-btn" lay-submit lay-filter="formSubmit">确认提交</button>
</div>
</div>
</div>
{include file="public/loading"/}
{include file="public/footer"/}
<script>
    layui.use(['layer', 'form','element'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;

        // 监听开关
        form.on('switch', function(data){
            var elemId = data.elem.attributes['lay-filter']['nodeValue'];
            if (data.elem.checked) {
                this.value = 1;
            } else {
                this.value = 0;
            }
            $("#"+elemId).val(this.value);
        });

        form.on('submit(sendSms)', function(data) {
            if (data.field.sms_test == '') {
                layer.msg('接收手机号码不能为空！', {time:1000});
                $('input[name=sms_test]').focus();
                return false;
            } else {
                layer.msg('正在处理请勿刷新页面', {icon: 16,shade: 0.01,time:3600000});
                $.ajax({
                    type: "post",
                    data: {mobile:data.field.sms_test},
                    dataType: 'json',
                    url: "{:url('/web/send_sms')}",
                    success: function(res) {
                        layer.closeAll();
                        if(res.status){
                            layer.msg(res.msg, {icon:1,time:1000});
                        }else{
                            layer.msg(res.msg, {icon:2,time:1000});
                        }
                    },
                    error: function() {
                        layer.closeAll();
                        layer.msg("网络中断！", {icon: 2,time:1000});
                    }
                })
            }
            return false;
        });
        
        //监听提交
        form.on('submit(formSubmit)', function(data){
            layer.msg('正在处理请勿刷新页面', {icon: 16,shade: 0.01});
            $.ajax({
                type : 'post',
                url : "{:url('/web/weapp_sms')}",
                data : data.field,
                dataType : 'json',
                success : function(res){
                    layer.closeAll();
                    if(res.status){
                        layer.msg(res.msg, {icon:1,time:1000}, function(){
                            window.location.reload();
                        });
                    }else{
                       layer.msg(res.msg, {icon:2,time:1000});
                    }
                },
                error: function(e){
                    layer.closeAll();
                    layer.msg("网络中断！", {icon: 2,time:1000});
                }
            });
            return false;
        });

    });
</script>
</body>
</html>